class Solution {
public:
    bool canJump(vector<int>& nums) {
        int n = nums.size();
        int jumpLen = 0;
        for (int i = 0; i < n; i++)
        {
            if (i > jumpLen)
                return false;
            jumpLen = max(jumpLen, i + nums[i]);
            if (jumpLen >= n - 1)
                return true;
        }
        return true;
    }
};